document.write("<script type='text/javascript' src='js/jquery-2.0.0.js'></script>");
document.write("<script type='text/javascript'  src='layer/layer.js'></script>");
document.write("<script type='text/javascript' src='layer/extend/layer.ext.js'></script>");
$(document).ready(function(){
	
	$("#zhoubao").click(function(){				
		$(".kuang3").html("<div class='d1'></div><div class='tou1'></div><div class='tou2'></div><div class='tou3'></div>" );
	    $(".d1").append("<p class='font'>当前位置：项目管理--->项目周报</p>");
	    $(".tou3").html("<h style='color:#3786c7;font-weight:blod; font-size:16px'>总共有<h id='number'></h>条数据,每页显示5条数据</h>&nbsp;<input type='button' value='上一页'   onClick='zhoubaoshangyiye()' class='jihuabutton'>&nbsp<h id='page'>1</h>&nbsp<input type='button' value='下一页' onClick='zhoubaoxiayiye()'  class='jihuabutton'>");
	   
	    
	    $.ajax({
        	type:'post',
			data:'',
			async:false,
			url:"project.do",
			dataType:'json',
			success:function(data){
				$(".tou1").append("<div class='tianjiajihua' id='xjzb'>新建周报</div><h class='select'>选择项目:</h><select class='projectselect' onChange='zhoubao1()' name='project' id='project'></select><input class='sousuo' type='text'><div class='sousuobutton'>搜索</div>");	 
				for(var i=0;i<data.length;i++){
					$("#project").append("<option>"+data[i].projectName+"</option>");	
				}	
	    
	    $("#xjzb").click(function(){
//	    	alert($("#project").val());
			layer.open({
				  type: 1,
				  skin: 'layui-layer-demo',
				  area: ['400px', '200px'], //宽高
				  shadeClose: true,
				  content: 
					  	"<form id='xjzb_zhoubao' method='post'><br>"
					    +"<center>完成情况:<input type='text';  style='border:1px #000 solid; outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='completion' id='completion' ></center><br><br>" 
		    			+"<center>下周计划:<input type='text'; style='border:1px #000 solid;outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='nextPlan' id='nextPlan' ></center><br><br>" 		    			
		    			+"<center>问题汇总:<input type='text'; style='border:1px #000 solid;outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='problemAll' id='problemAll'></center><br><br>" 
		    			+" <input type='hidden' value="+$("#project").val()+" name='project'>"
		    			+"<center><input type='button' style='background:#0066ff;color:#ffffff;width:70px;height:30px' value='添加' name='添加' class='tianjia' onClick='zhoubaotianjia()'></center>"
		    			+"</form>"
				 });
			
		});
			}
        });
	   zhoubaopage();
	   
		zhoubao();
		
});
		  
});

function zhoubaoshanchu(){
	 $.ajax({
			type:'post',
			data:$("#shanchu_zhoubao").serialize(),
			url:"shanchu_zb.do",
			dataType:'json',
			success:function(data){
				 layer.closeAll();
				 zhoubaopage();
			     zhoubao();
			}
		});
}
function zhoubaoxiugai(){
	//alert("1");
	 $.ajax({
			type:'post',
			data:$("#xiugai_zhoubao").serialize(),
         url:"xiugai_zb.do",
			dataType:'json',
			success:function(data){
				
				 layer.closeAll();
				zhoubaopage();
			     zhoubao();
			}
		});
}
function zhoubaotianjia(){
	if($("#completion").val()==""||$("#nextPlan").val()==""||$("#problemAll").val()==""){
		alert("信息不能为空!");
	}else{
		$.ajax({
			type:'post',
			data:$("#xjzb_zhoubao").serialize(),
            url:"xinjian_zb.do",
			dataType:'json',
			success:function(data){
				 layer.closeAll();
				 zhoubaopage();
			     zhoubao();
			     
			}
		});	
	}
}
function zhoubao1(){
	zhoubaopage();
	$("#page").html("1");
	zhoubao();
}
function zhoubaopage(){
	 $.ajax({
     	type:'post',
			data:{"project":$("#project").val()},
			async:false,
			url:"zhoubaopage.do",
			dataType:'json',
			success:function(data){
				$("#number").html(data.num);
			}
			});
}
function zhoubaoshangyiye(){
	
	var page=$("#page").html();
	if(page==1){
		alert("已经是第一页了");
	}
	else{
		page=page-1;
		
		$("#page").html(page);
		zhoubao();
	}
}
function zhoubaoxiayiye(){
	
	var page=$("#page").html();
	var number=$("#number").html();
	var zong= parseInt(number/5);
	if(!(number%5)){
		
	}else{
	zong++;
	}
	
	if(page==zong||number==0){
		alert("已经是最后一页了");
	}
	
	else{
		page++;
		$("#page").html(page);
		
		zhoubao();
		
	}
}

function zhoubao(){
	//alert("1");
	 $.ajax({
			type:'post',
			data:{"page":$("#page").html(),"project":$("#project").val()},
            url:"zhoubao.do",
			dataType:'json',
			success:function(data){
				if(data.length==0){
					$(".tou2").html("暂无记录");
				}
				else{$(".tou2").html("");
				$(".tou2").append("<table class='hovertable' style='width:840px'>");
	    	
				$(".tou2").append("<tr>" 
	    			+"		<th scope='col' style='width: 250px; '><center>完成情况</center></th>" 
	    			+"		<th scope='col' style='width: 250px; '><center>下周计划</center></th>" 
	    			+"		<th scope='col' style='width: 250px; '><center>问题汇总</center></th>" 
	    			+"		<th scope='col' style='width: 250px; '><center>创建时间</center></th>"
					+"		<th scope='col' style='width: 100px; '><center>修改</center></th>"
					+"		<th scope='col' style='width: 100px; '><center>删除</center></th> 	"		 			
					+"	</tr>");							    		    		
				for(var i=0;i<data.length;i++){	
				
					$(".tou2").append("<tr>"
					+"		<td class='row'><center>"+data[i].completion+"</center></td>"
					+"		<td class='row'><center>"+data[i].nextPlan+"</center></td>"
					+"		<td class='row'><center>"+data[i].problemAll+"</center></td>"
					+"		<td class='row'><center>"+data[i].createTime+"</center></td>"
					+"		<td class='row' id='"+i+"' name='xiugai'><center><img src='images/mod.gif'></center></td>"
					+"		<td class='row' id='"+i+"' name='shanchu''><center><img src='images/del.gif'></img></center></td>"
					+"	</tr>"	);	
	    	
				}
				$(".tou2").append("</table>");	    		
				$(".tou2").append("<div style='height:15px'></div>");
				
	    	  
	    	
	    	$("td[name='xiugai']").click(function(){
	    		var id=this.id;
	    		layer.open({
					  type: 1,
					  skin: 'layui-layer-demo',
					  area: ['400px', '250px'], //宽高
					  shadeClose: true,
					  
					  content: 
						  
						  "<form id='xiugai_zhoubao' method='post'>"					  
							+"<input type='hidden'; style='border:0px' name='planId_xiugai' value='"+data[id].planId+"' ><br><br>" 
						    +"<center>完成情况:<input type='text'; style='border:1px #000 solid; outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='completion_xiugai' value='"+data[id].completion+"'></center><br><br>" 
			    			+"<center>下周计划:<input type='text'; style='border:1px #000 solid; outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='nextPlan_xiugai' value='"+data[id].nextPlan+"'></center><br><br>" 
			    			+"<center>问题汇总:<input type='text'; style='border:1px #000 solid; outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='problemAll_xiugai' value='"+data[id].problemAll+"'></center><br><br>" 
			    			+"<center><input type='button' style='background:#0066ff;color:#ffffff;width:70px;height:30px' value='修改' name='修改' class='tianjia' onClick='zhoubaoxiugai()'></center>"
			    			+"</form>"
					 });
	    	});
	    	
	    	
	    	$("td[name='shanchu']").click(function(){	
	    		var id=this.id;
	    		layer.open({
					  type: 1,
					  skin: 'layui-layer-demo',
					  area: ['400px', '270px'], //宽高
					  shadeClose: true,					  
					  content: "<form id='shanchu_zhoubao' method='post'>"
							+"<input type='hidden'; style='border:0px ' name='planId_shanchu' value='"+data[id].planId+"'  readonly><br><br>" 
							  +"<center>完成情况:<input type='text'; style='border:1px #000 solid; outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='completion_shanchu' value='"+data[id].completion+"'></center><br><br>" 
				    			+"<center>下周计划:<input type='text'; style='border:1px #000 solid; outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='nextPlan_shanchu' value='"+data[id].nextPlan+"'></center><br><br>" 
				    			+"<center>问题汇总:<input type='text'; style='border:1px #000 solid; outline:none; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: solid' name='problemAll_shanchu' value='"+data[id].problemAll+"'></center><br><br>" 
				    			+" <center> &nbsp; &nbsp;<input type='text' value='你确定删除该数据么？' style='border:0px'></center><br>"
			    			+"	<center><input type='button' style='background:#0066ff;color:#ffffff;width:70px;height:30px' value='删除' name='删除' class='tianjia' onClick='zhoubaoshanchu()'></center>"
						  		+"</form>"
						  
				 });
	    	});
	    	
	    }
			}
	});
	 

		event.stopPropagation();

   
}
